const { insertData, findData, updateData, deleteOneData, requstPromise, randomWord } = require('../utils')
const { updateUserInfo } = require('./user')
const crypto = require('crypto')

const Goods = {
    // 
    async addGoods(option) {
        const { describe, describePic, title, price } = option
        return requstPromise(await insertData('camluniGoods', {
            id: randomWord(false, 43),
            describe,
            describePic,
            title,
            price
        }))
    },

    // 删除指定id
    async deleteGoods(id) {
        return requstPromise(await deleteOneData('camluniGoods', { id }))
    },

    // 
    async editGoods(option) {
        const { id, ...data } = option
        return requstPromise(await updateData('camluniGoods', { id }, { ...data }))
    },

    // 获取列表
    async findGoods(option) {
        const { pageIndex, pageSize, ...options } = option
        console.log('camluniGoods', { ...options }, {}, parseFloat(pageIndex) - 1, parseFloat(pageSize))
        return requstPromise(await findData('camluniGoods', { ...options }, {}, parseFloat(pageIndex) - 1, parseFloat(pageSize)))
    },
}

module.exports = Goods
